home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * This file contains the functions which initialize the core
- * AppleEvents for the program.
- **********************************************************************/
-
- #include "Creator Changer.h"
- #include "Creator Changer.AE.h"
-
-
- /**********************************************************************
- * Function Install_AE_Handlers(), this function sets up the
- * AppleEvents for the program.
- **********************************************************************/
-
- void Install_AE_Handlers(void)
- {
-
- AEEventHandlerUPP open_ae, quit_ae, start_ae, print_ae;
-
- open_ae=NewAEEventHandlerProc(Open_AE);
- quit_ae=NewAEEventHandlerProc(Quit_AE);
- start_ae=NewAEEventHandlerProc(Start_AE);
- print_ae=NewAEEventHandlerProc(Print_AE);
-
- AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, open_ae, FALSE, FALSE);
- AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, quit_ae, FALSE, FALSE);
- AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, start_ae, FALSE, FALSE);
- AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, print_ae, FALSE, FALSE);
-
- }
-
-
-
- /**********************************************************************
- * Function Open_AE(), this function supports what happens when a file
- * is dropped on Creator Changer.
- **********************************************************************/
-
- pascal OSErr Open_AE(AppleEvent *the_event, AppleEvent *the_reply, long ref_con)
- {
-
- AEDescList the_files;
- long num_of_files;
-
- AEGetParamDesc(the_event, keyDirectObject, typeAEList, &the_files);
- AECountItems(&the_files, &num_of_files);
- Done_With_Dialog=NO;
-
- if(!FrontWindow())
- {
- if((**Global).AutoChange && Option_Key_Down) Open_Auto_Change_Files(the_files, num_of_files);
- else Open_Normal_Files(the_files, num_of_files);
- if((**Global).DragQuit==TRUE) All_Done=TRUE;
- }
- else Do_Error(Multi_File_1, EMPTY_STR, Multi_File_2, Multi_File_3);
-
- Maintain_Menu_Items(FrontWindow());
- return(noErr);
-
- }
-
-
-
- /**********************************************************************
- * Function Open_Auto_Change_Files(), this function opens the files which are
- * dropped on CC and when the Automatic change box is checked. If there are files
- * which are not specified in the types listing, then CC will open them with the
- * normal Change Dialog. I do this by starting another Event Loop, until
- * the user closes out the Dialog.
- **********************************************************************/
-
- void Open_Auto_Change_Files(AEDescList the_files, long num_of_files)
- {
-
- AEKeyword key_word;
- DescType the_type;
- Size the_size;
- auto_chng **rsrc_handle;
- Str4 types[100];
- short i, the_item=1;
-
-
- Make_Pop_Up_Menu(Auto.menu_id, PREF_AC, Auto.num_items);
- Get_Types_From_Prefs(types);
- for(i=1;i<=num_of_files;i++)
- {
- Multiple_Files=NO;
- AEGetNthPtr(&the_files, i, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
- FSpGetFInfo(&The_File_Spec, &File_Info);
- the_item=Check_File_Type(types, File_Info.fdType);
- if(the_item)
- {
- UseResFile(CreatorChangerPref);
- rsrc_handle=(auto_chng **)GetResource(PREF_AC, The_ac_Type[the_item]);
- Set_Type_Long((**rsrc_handle).ToFile, &File_Info.fdType, NIL_PTR, NIL_PTR);
- Set_Type_Long((**rsrc_handle).ToCreator, &File_Info.fdCreator, NIL_PTR, NIL_PTR);
- ReleaseResource((Handle)rsrc_handle);
- UseResFile(CreatorChangerApp);
- FSpSetFInfo(&The_File_Spec, &File_Info);
- Force_Finder_Update(&The_File_Spec);
- }
- else
- {
- Chng.files=the_files;
- Chng.num_files=one_file;
- Open_DLOG(&Chng);
-
- while(!Done_With_Dialog) Handle_One_Event();
- }
- }
- AEDisposeDesc(&the_files);
-
- }
-
-
-
- /**********************************************************************
- * Function Open_Normal_Files(), this function this function opens the files if
- * the Automatic Change box was NOT checked. Once again I start another Event
- * Loop until the user closes the Change Dialog.
- **********************************************************************/
-
- void Open_Normal_Files(AEDescList the_files, long num_of_files)
- {
-
- AEKeyword key_word;
- DescType the_type;
- Size the_size;
-
- if(num_of_files==1)
- {
- Multiple_Files=NO;
- AEGetNthPtr(&the_files, 1, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
- FSpGetFInfo(&The_File_Spec, &File_Info);
- AEDisposeDesc(&the_files);
- }
- else Multiple_Files=YES;
-
- Chng.files=the_files;
- Chng.num_files=num_of_files;
- Open_DLOG(&Chng);
-
- while(!Done_With_Dialog) Handle_One_Event();
-
- Multiple_Files=NO;
-
- }
-
-
-
- /**********************************************************************
- * Function Get_Types_From_Prefs(), this function gets the types from
- * preference file and stores them in an array, for later use.
- **********************************************************************/
-
- void Get_Types_From_Prefs(Str4 *the_array)
- {
-
- short i;
- auto_chng **the_handle;
-
- the_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
- UseResFile(CreatorChangerPref);
- for(i=1;i<=Auto.num_items;i++)
- {
- the_handle=(auto_chng **)GetResource(PREF_AC, The_ac_Type[i]);
- p_Str_Copy((**the_handle).FromFile, the_array[i]);
- ReleaseResource((Handle)the_handle);
- }
- UseResFile(CreatorChangerApp);
-
- }
-
-
-
- /**********************************************************************
- * Function Check_File_Type(), this function checks the current file's
- * file type against those in the types list, if the type is not there then it
- * returns BAD, else it returns the menu index at which it found the type.
- **********************************************************************/
-
- short Check_File_Type(Str4 *the_arry, OSType the_ostype)
- {
-
- short i;
- Str4 the_text_type;
-
- Set_Type_Text(the_text_type, the_ostype);
-
- for(i=1;i<=Auto.num_items;i++) if(Comp_The_String(the_arry[i], the_text_type)) return(i);
- return(BAD);
-
- }
-
-
-
- /**********************************************************************
- * Function Quit_AE(), this function supports the 'quit' event. All
- * that it does is set the global switch to true to quit.
- **********************************************************************/
-
- pascal OSErr Quit_AE(AppleEvent *theEvent, AppleEvent *reply, long ref_con)
- {
-
- All_Done=TRUE;
- return(noErr);
-
- }
-
-
-
- /**********************************************************************
- * Function Print_AE(), this function does nothing, besides report
- * that CC does not support the print event.
- **********************************************************************/
-
- pascal OSErr Print_AE(AppleEvent *theEvent, AppleEvent *reply, long ref_con)
- {
-
- return(errAEEventNotHandled);
-
- }
-
-
-
- /**********************************************************************
- * Function Start_AE(), this function controls what happens when
- * Creator Changer is launched.
- **********************************************************************/
-
- pascal OSErr Start_AE(AppleEvent *theEvent, AppleEvent *reply, long ref_con)
- {
-
- Handle_File_Choice(F_OPEN_ITEM);
- return(noErr);
-
- }